package com.java.throwable;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

/**
 * try-with-resource
 */
public class TryWithResource {
    public static void main(String[] args) {
        File file = new File("");
        
        // try-catch-finally
        FileInputStream fileInputStream1 = null;
        try {
            fileInputStream1 = new FileInputStream(file);
        } catch (IOException e) {
        
        } finally {
            if (fileInputStream1 != null) {
                try {
                    fileInputStream1.close();
                } catch (IOException e) {}
            }
        }
        
        // try-with-resource
        try (
                FileInputStream fileInputStream2 = new FileInputStream(file);
        ) {
            // try语句
        } catch (IOException e) {
            e.getSuppressed(); // 获取被抑制的异常
        }
    }
}
